<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    
</body>
<script>

    const promise = new Promise(function(resolve,reject){
        // 耗时操作
        // ...
        
        if(true){
            resolve('success')
        }else{
            reject('error')
        }
    })
    promise.then(function(data){
        console.log(data)
    },function(error){
        console.log(error)
    })
    console.log('后台继续执行')



    //使用场景
    (function(){
        return new Promise(function(resolve,reject){
            if(true){
                resolve('success')
            }else{
                reject('error')
            }
        })
    })().then(function(data){
        console.log(data)
    },function(error){
        console.log(error)
    })

</script>
</html>